package com.dynamixsoftware.printershare;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.dynamixsoftware.printershare.bjnp.BJNPSocket;
import com.dynamixsoftware.printershare.data.Printer;
import com.dynamixsoftware.printershare.data.SoapEnvelope;
import com.dynamixsoftware.printershare.data.SoapService;
import com.dynamixsoftware.printershare.data.User;
import com.dynamixsoftware.printershare.data.XmlUtil;
import com.dynamixsoftware.printershare.ipp.IppAttribute;
import com.dynamixsoftware.printershare.ipp.IppConnection;
import com.dynamixsoftware.printershare.ipp.IppMessage;
import com.dynamixsoftware.printershare.smb.SmbFile;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.UUID;
import java.util.Vector;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class ActivityStart  extends ActivityCore
{
  private static final int DIALOG_LOGIN = 2;
  private static final int DIALOG_REGISTER = 1;
  private Vector<Printer> cloud_printers;
  private Vector<Printer> local_printers;
  protected Handler scanHandler = new Handler()
  {
    public void handleMessage(Message paramAnonymousMessage)
    {
      label787:
      for (;;)
      {
        try
        {
          switch (paramAnonymousMessage.what)
          {
          case 1: 
          case 2: 
          default: 
            super.handleMessage(paramAnonymousMessage);
            return;
          }
          if (paramAnonymousMessage.arg1 == 0)
          {
            if (ActivityStart.this.st_bonjour != null) {
              ActivityStart.this.local_printers.addAll(ActivityStart.this.st_bonjour.getPrinters());
            }
            ActivityStart.access$102(ActivityStart.this, null);
            if ((ActivityStart.this.st_bonjour != null) || (ActivityStart.this.st_snmp != null) || (ActivityStart.this.st_bjnp != null) || (ActivityStart.this.st_wsd != null) || (ActivityStart.this.st_tpl != null) || (ActivityStart.this.st_bluetooth != null) || (ActivityStart.this.st_usb != null)) {
              break label557;
            }
            ActivityCore.token = ActivityStart.this.prefs.getString("token", "");
            if (ActivityCore.token.length() <= 0) {
              break label534;
            }
            ActivityStart.access$902(ActivityStart.this, new ActivityStart.LoginThread(ActivityStart.this, 3));
            ActivityStart.this.wt.start();
            continue;
          }
          if (paramAnonymousMessage.arg1 != 1) {
            break label278;
          }
        }
        finally {}
        if (ActivityStart.this.st_snmp != null) {
          ActivityStart.this.local_printers.addAll(ActivityStart.this.st_snmp.getPrinters());
        }
        ActivityStart.access$302(ActivityStart.this, null);
        continue;
        label278:
        if (paramAnonymousMessage.arg1 == 2)
        {
          if (ActivityStart.this.st_bjnp != null) {
            ActivityStart.this.local_printers.addAll(ActivityStart.this.st_bjnp.getPrinters());
          }
          ActivityStart.access$402(ActivityStart.this, null);
        }
        else if (paramAnonymousMessage.arg1 == 3)
        {
          if (ActivityStart.this.st_bluetooth != null) {
            ActivityStart.this.local_printers.addAll(ActivityStart.this.st_bluetooth.getPrinters());
          }
          ActivityStart.access$502(ActivityStart.this, null);
        }
        else if (paramAnonymousMessage.arg1 == 4)
        {
          if (ActivityStart.this.st_usb != null) {
            ActivityStart.this.local_printers.addAll(ActivityStart.this.st_usb.getPrinters());
          }
          ActivityStart.access$602(ActivityStart.this, null);
        }
        else if (paramAnonymousMessage.arg1 == 5)
        {
          if (ActivityStart.this.st_wsd != null) {
            ActivityStart.this.local_printers.addAll(ActivityStart.this.st_wsd.getPrinters());
          }
          ActivityStart.access$702(ActivityStart.this, null);
        }
        else if (paramAnonymousMessage.arg1 == 6)
        {
          if (ActivityStart.this.st_tpl != null) {
            ActivityStart.this.local_printers.addAll(ActivityStart.this.st_tpl.getPrinters());
          }
          ActivityStart.access$802(ActivityStart.this, null);
          continue;
          label534:
          ActivityStart.access$902(ActivityStart.this, new ActivityStart.LoginThread(ActivityStart.this, 4));
          continue;
          label557:
          String str = ActivityStart.this.prefs.getString("printer", null);
          if (str != null) {
            str = str.split("\\|")[0];
          }
          for (;;)
          {
            if (i >= ActivityStart.this.local_printers.size()) {
              break label787;
            }
            if (((Printer)ActivityStart.this.local_printers.get(i)).id.equals(str))
            {
              if (ActivityStart.this.st_bonjour != null) {
                ActivityStart.this.st_bonjour.destroy();
              }
              if (ActivityStart.this.st_snmp != null) {
                ActivityStart.this.st_snmp.destroy();
              }
              if (ActivityStart.this.st_bjnp != null) {
                ActivityStart.this.st_bjnp.destroy();
              }
              if (ActivityStart.this.st_wsd != null) {
                ActivityStart.this.st_wsd.destroy();
              }
              if (ActivityStart.this.st_tpl != null) {
                ActivityStart.this.st_tpl.destroy();
              }
              if (ActivityStart.this.st_bluetooth != null) {
                ActivityStart.this.st_bluetooth.destroy();
              }
              if (ActivityStart.this.st_usb == null) {
                break;
              }
              ActivityStart.this.st_usb.destroy();
              break;
            }
            i++;
            continue;
            int i = 0;
          }
        }
      }
    }
  };
  private ScanThreadBJNP st_bjnp;
  private ScanThreadBluetooth st_bluetooth;
  private ScanThreadBonjour st_bonjour;
  private ScanThreadSNMP st_snmp;
  private ScanThreadTPL st_tpl;
  private ScanThreadUSB st_usb;
  private ScanThreadWSD st_wsd;
  private View view_dialog_login;
  private View view_dialog_register;
  private PowerManager.WakeLock wl;
  private Thread wt;
  
  private void do_finish(int paramInt)
  {
    String str1;
    Object localObject;
    Printer localPrinter4;
    int k;
    if (paramInt == -1)
    {
      str1 = this.prefs.getString("printer", "");
      localObject = null;
      if (str1 != null)
      {
        String[] arrayOfString4 = str1.split("\\|");
        str1 = arrayOfString4[0];
        if (arrayOfString4.length <= 1) {
          break label411;
        }
        localObject = arrayOfString4[1];
      }
      if (!str1.endsWith(".local.")) {
        break label1130;
      }
      if (this.local_printers != null) {
        if (printer != null)
        {
          String str8 = printer.id;
          if (str1.equals(str8)) {}
        }
        else
        {
          printer = null;
          localPrinter4 = null;
          k = 0;
          label99:
          if (k < this.local_printers.size())
          {
            localPrinter4 = (Printer)this.local_printers.get(k);
            if (!localPrinter4.id.equals(str1)) {
              break label416;
            }
          }
          if (localPrinter4 != null) {
            if (localObject != null)
            {
              localPrinter4.model = localObject;
              localPrinter4.drv_manual = true;
            }
          }
        }
      }
    }
    label411:
    label416:
    label1204:
    label1605:
    for (;;)
    {
      try
      {
        boolean bool;
        if (localPrinter4.direct_address.startsWith("ipp://"))
        {
          IppConnection localIppConnection = new IppConnection(localPrinter4.direct_address, App.getUserAgent());
          localPrinter4.owner.login = this.prefs.getString("printer_login", null);
          localPrinter4.owner.password = this.prefs.getString("printer_password", null);
          IppMessage localIppMessage = new IppMessage(IppMessage.OP_GET_PRINTER_ATTRIBUTES);
          localIppMessage.operation_attributes.add(new IppAttribute((byte)71, "attributes-charset", "utf-8"));
          localIppMessage.operation_attributes.add(new IppAttribute((byte)72, "attributes-natural-language", "en-us"));
          localIppMessage.operation_attributes.add(new IppAttribute((byte)69, "printer-uri", localIppConnection.getUri()));
          localIppConnection.sendRequest(localIppMessage);
          int n = localIppConnection.getResponse().code;
          bool = false;
          if (n == 0) {
            bool = true;
          }
          if ((bool) && ((localPrinter4.direct_address.startsWith("ptp://")) || ((findDriver(localPrinter4) != 0) && ((localPrinter4.drv_name.startsWith("internal")) || (drvCheck(localPrinter4)))))) {
            printer = localPrinter4;
          }
          setPrinter(printer);
          setResult(paramInt);
          finish();
          return;
          localObject = null;
          break;
          if (str1.length() > 0) {
            localPrinter4 = null;
          }
          k++;
          break label99;
        }
        if (localPrinter4.direct_address.startsWith("bjnp://"))
        {
          URL localURL1 = new URL(localPrinter4.direct_address.replaceAll("bjnp", "http"));
          bool = new BJNPSocket().check(new InetSocketAddress(localURL1.getHost(), localURL1.getPort()), 15000);
          continue;
        }
        if (localPrinter4.direct_address.startsWith("pdl://"))
        {
          URL localURL2 = new URL(localPrinter4.direct_address.replaceAll("pdl", "http"));
          Socket localSocket1 = new Socket();
          localSocket1.connect(new InetSocketAddress(localURL2.getHost(), localURL2.getPort()), 15000);
          localSocket1.close();
          bool = true;
          continue;
        }
        if (localPrinter4.direct_address.startsWith("wprt://"))
        {
          String str7 = localPrinter4.direct_address.replaceAll("wprt", "http");
          URL localURL4 = new URL(str7);
          HttpURLConnection localHttpURLConnection = (HttpURLConnection)localURL4.openConnection();
          localHttpURLConnection.setConnectTimeout(15000);
          localHttpURLConnection.setReadTimeout(15000);
          localHttpURLConnection.setDoInput(true);
          localHttpURLConnection.setDoOutput(true);
          localHttpURLConnection.setUseCaches(false);
          localHttpURLConnection.setRequestMethod("POST");
          localHttpURLConnection.setRequestProperty("Content-Type", "application/soap+xml");
          localHttpURLConnection.getOutputStream().write(("<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsdp=\"http://schemas.xmlsoap.org/ws/2005/05/devprof\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:wprt=\"http://schemas.microsoft.com/windows/2006/08/wdp/print\"><soap:Header><wsa:To>" + str7 + "</wsa:To><wsa:Action>http://schemas.microsoft.com/windows/2006/08/wdp/print/GetPrinterElements</wsa:Action><wsa:MessageID>urn:uuid:" + UUID.randomUUID() + "</wsa:MessageID><wsa:ReplyTo><wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address></wsa:ReplyTo></soap:Header><soap:Body><wprt:GetPrinterElementsRequest><wprt:RequestedElements><wprt:Name>wprt:PrinterStatus</wprt:Name></wprt:RequestedElements></wprt:GetPrinterElementsRequest></soap:Body></soap:Envelope>").getBytes());
          int i3 = localHttpURLConnection.getResponseCode();
          bool = false;
          if (i3 != 200) {
            continue;
          }
          bool = true;
          continue;
        }
        if (localPrinter4.direct_address.startsWith("lpd://"))
        {
          URL localURL3 = new URL(localPrinter4.direct_address.replaceAll("lpd", "http"));
          Socket localSocket2 = new Socket();
          localSocket2.connect(new InetSocketAddress(localURL3.getHost(), localURL3.getPort()), 15000);
          localSocket2.setSoTimeout(15000);
          OutputStream localOutputStream = localSocket2.getOutputStream();
          localOutputStream.write(2);
          localOutputStream.write((localURL3.getPath().substring(1) + "\n").getBytes());
          localOutputStream.flush();
          int i2 = localSocket2.getInputStream().read();
          localOutputStream.write(1);
          localOutputStream.write("\n".getBytes());
          localSocket2.close();
          bool = false;
          if (i2 != 0) {
            continue;
          }
          bool = true;
          continue;
        }
        if (localPrinter4.direct_address.startsWith("usb://"))
        {
          final String[] arrayOfString3 = localPrinter4.direct_address.substring(6).split("\\|");
          final boolean[] arrayOfBoolean = new boolean[1];
          new Object(); {};
          i1 = arrayOfBoolean[0];
          continue;
        }
        int i1 = 1;
        continue;
      }
      catch (Exception localException3)
      {
        String str5 = localException3.getMessage();
        if ((str5 != null) && (str5.indexOf("HTTP error 404") != -1) && (localPrinter4.direct_address.indexOf(":631/ipp") < 0))
        {
          int m = localPrinter4.direct_address.indexOf(":631");
          String str6 = localPrinter4.direct_address.substring(0, m + 4) + "/ipp" + localPrinter4.direct_address.substring(m + 4);
          localPrinter4.direct_address = str6;
          continue;
        }
        localException3.printStackTrace();
        App.reportThrowable(localException3);
        continue;
      }
      label1130:
      if (str1.endsWith("cloudprint.google."))
      {
        printer = null;
        if (this.cloud_printers != null) {
          for (int j = 0;; j++)
          {
            if (j >= this.cloud_printers.size()) {
              break label1204;
            }
            Printer localPrinter3 = (Printer)this.cloud_printers.elementAt(j);
            if (localPrinter3.id.equals(str1))
            {
              printer = localPrinter3;
              break;
            }
          }
        }
      }
      else
      {
        String[] arrayOfString1;
        Printer localPrinter2;
        String str4;
        if (str1.startsWith("smb://"))
        {
          printer = null;
          for (;;)
          {
            try
            {
              String str2 = this.prefs.getString("smb_auth", null);
              if (str2 != null)
              {
                str3 = "smb://" + str2 + "@" + str1.substring(6);
                localSmbFile = new SmbFile(str3);
              }
            }
            catch (Exception localException1)
            {
              SmbFile localSmbFile;
              String[] arrayOfString2;
              localException1.printStackTrace();
              App.reportThrowable(localException1);
            }
            try
            {
              arrayOfString2 = localSmbFile.printerGetInfo();
              arrayOfString1 = arrayOfString2;
            }
            catch (Exception localException2)
            {
              localException2.printStackTrace();
              App.reportThrowable(localException2);
              arrayOfString1 = null;
              continue;
              localPrinter2.model = str4;
              continue;
            }
            localPrinter2 = new Printer();
            localPrinter2.owner = new User();
            localPrinter2.capabilities = new Hashtable();
            localPrinter2.online = true;
            str4 = localSmbFile.getName();
            if (str4.endsWith("/")) {
              str4 = str4.substring(0, -1 + str4.length());
            }
            localPrinter2.id = str1;
            localPrinter2.title = str4;
            localPrinter2.direct_address = str3;
            localPrinter2.owner.name = localSmbFile.getServer();
            if (arrayOfString1 == null) {
              break label1536;
            }
            localPrinter2.model = arrayOfString1[1];
            localPrinter2.location = arrayOfString1[2];
            if (localObject != null)
            {
              localPrinter2.model = localObject;
              localPrinter2.drv_manual = true;
            }
            localSmbFile.print_open("");
            localSmbFile.print_close();
            if ((findDriver(localPrinter2) == 0) || ((!localPrinter2.drv_name.startsWith("internal")) && (!drvCheck(localPrinter2)))) {
              break;
            }
            printer = localPrinter2;
            break;
            break;
            String str3 = str1;
          }
        }
        printer = null;
        if (remote_printers != null) {
          for (int i = -1 + remote_printers.size();; i--)
          {
            if (i < 0) {
              break label1605;
            }
            Printer localPrinter1 = (Printer)remote_printers.elementAt(i);
            printer = localPrinter1;
            if (localPrinter1.id.equals(str1)) {
              break;
            }
          }
        }
      }
    }
  }
  
  private void setOrientation(int paramInt)
  {
    int i = 1;
    LinearLayout localLinearLayout1 = (LinearLayout)findViewById(2131230819);
    int j;
    LinearLayout localLinearLayout2;
    if (paramInt == i)
    {
      j = i;
      localLinearLayout1.setOrientation(j);
      localLinearLayout2 = (LinearLayout)findViewById(2131230821);
      if (paramInt != i) {
        break label57;
      }
    }
    for (;;)
    {
      localLinearLayout2.setOrientation(i);
      return;
      j = 0;
      break;
      label57:
      i = 0;
    }
  }
  
  private void start_init()
  {
    findViewById(2131230819).setVisibility(8);
    findViewById(2131230821).setVisibility(8);
    findViewById(2131230824).setVisibility(0);
    if (token == null)
    {
      this.local_printers = new Vector();
      this.cloud_printers = new Vector();
      String str = this.prefs.getString("printer", null);
      if (str != null) {
        str = str.split("\\|")[0];
      }
      if ((str != null) && (str.endsWith(".local.")))
      {
        if (str.indexOf("_usb.") > 0)
        {
          this.st_usb = new ScanThreadUSB(getApplicationContext(), 5000, str, this.scanHandler);
          this.st_usb.start();
          return;
        }
        if (str.indexOf("_bluetooth.") > 0)
        {
          this.st_bluetooth = new ScanThreadBluetooth(getApplicationContext(), 5000, str, this.scanHandler);
          this.st_bluetooth.start();
          return;
        }
        this.st_bonjour = new ScanThreadBonjour(getApplicationContext(), 5000, str, this.scanHandler);
        this.st_bonjour.start();
        this.st_snmp = new ScanThreadSNMP(getApplicationContext(), 5000, str, this.scanHandler);
        this.st_snmp.start();
        this.st_bjnp = new ScanThreadBJNP(getApplicationContext(), 5000, str, this.scanHandler);
        this.st_bjnp.start();
        this.st_wsd = new ScanThreadWSD(getApplicationContext(), 5000, str, this.scanHandler);
        this.st_wsd.start();
        this.st_tpl = new ScanThreadTPL(getApplicationContext(), 5000, str, this.scanHandler);
        this.st_tpl.start();
        return;
      }
      if ((str != null) && (str.endsWith("cloudprint.google.")))
      {
        this.wt = new CloudThread(str.substring(0, str.indexOf("@")));
        this.wt.start();
        return;
      }
      Message localMessage = new Message();
      localMessage.what = 4;
      localMessage.arg1 = -1;
      this.scanHandler.sendMessage(localMessage);
      return;
    }
    if (token.length() > 0)
    {
      this.wt = new LoginThread(3);
      this.wt.start();
      return;
    }
    findViewById(2131230819).setVisibility(8);
    findViewById(2131230821).setVisibility(0);
    findViewById(2131230824).setVisibility(8);
  }
  
  protected void init()
  {
    String str = this.prefs.getString("version", "");
    if (!App.getVersion().equals(str))
    {
      if (("6.5.0".equals(str)) || ("6.5.1".equals(str)) || ("6.6.0".equals(str)))
      {
        SharedPreferences.Editor localEditor = this.prefs.edit();
        localEditor.putBoolean("smb_nearby_hack", true);
        localEditor.commit();
      }
      findViewById(2131230819).setVisibility(0);
      findViewById(2131230821).setVisibility(8);
      findViewById(2131230824).setVisibility(8);
      return;
    }
    start_init();
  }
  
  public void onConfigurationChanged(Configuration paramConfiguration)
  {
    super.onConfigurationChanged(paramConfiguration);
    setOrientation(paramConfiguration.orientation);
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903071);
    setOrientation(getResources().getConfiguration().orientation);
    setTitle(2131099667);
    try
    {
      this.wl = ((PowerManager)getSystemService("power")).newWakeLock(6, "PrinterShare");
      this.wl.acquire();
      ((Button)findViewById(2131230822)).setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          ActivityStart.this.showDialog(1);
        }
      });
      ((Button)findViewById(2131230823)).setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          ActivityStart.this.showDialog(2);
        }
      });
      ((Button)findViewById(2131230722)).setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          Intent localIntent = new Intent();
          localIntent.setClass(ActivityStart.this, ActivityInfo.class);
          ActivityStart.this.startActivity(localIntent);
        }
      });
      ((Button)findViewById(2131230820)).setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          SharedPreferences.Editor localEditor = ActivityStart.this.prefs.edit();
          localEditor.putString("version", App.getVersion());
          localEditor.commit();
          ActivityStart.this.start_init();
        }
      });
      LayoutInflater localLayoutInflater = LayoutInflater.from(this);
      this.view_dialog_register = localLayoutInflater.inflate(2130903050, null);
      this.view_dialog_login = localLayoutInflater.inflate(2130903046, null);
      return;
    }
    catch (Exception localException)
    {
      for (;;)
      {
        localException.printStackTrace();
        App.reportThrowable(localException);
      }
    }
  }
  
  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default: 
      return null;
    case 1: 
      new AlertDialog.Builder(this).setIcon(2130837549).setTitle(2131099834).setView(this.view_dialog_register).setPositiveButton(2131099703, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
        {
          ActivityStart.this.findViewById(2131230819).setVisibility(8);
          ActivityStart.this.findViewById(2131230821).setVisibility(8);
          ActivityStart.this.findViewById(2131230824).setVisibility(0);
          new ActivityStart.LoginThread(ActivityStart.this, 1).start();
        }
      }).setNegativeButton(2131099707, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {}
      }).create();
    }
    ((EditText)this.view_dialog_login.findViewById(2131230739)).setText(this.prefs.getString("login", ""));
    new AlertDialog.Builder(this).setIcon(2130837549).setTitle(2131099838).setView(this.view_dialog_login).setPositiveButton(2131099703, new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        ActivityStart.this.findViewById(2131230819).setVisibility(8);
        ActivityStart.this.findViewById(2131230821).setVisibility(8);
        ActivityStart.this.findViewById(2131230824).setVisibility(0);
        new ActivityStart.LoginThread(ActivityStart.this, 2).start();
      }
    }).setNegativeButton(2131099707, new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {}
    }).create();
  }
  
  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    return false;
  }
  
  protected void onDestroy()
  {
    if (this.wl != null) {
      this.wl.release();
    }
    super.onDestroy();
  }
  
  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if ((paramInt == 4) && (findViewById(2131230819).getVisibility() == 8))
    {
      if (findViewById(2131230824).getVisibility() == 8) {
        do_finish(0);
      }
      return true;
    }
    return super.onKeyDown(paramInt, paramKeyEvent);
  }
  
  protected void onResume()
  {
    super.onResume();
    setTitle(getResources().getString(2131099667) + getTitleSuffix());
  }
  
  class CloudThread
    extends Thread
  {
    private String pid;
    
    public CloudThread(String paramString)
    {
      this.pid = paramString;
    }
    
    public void run()
    {
      try
      {
        BasicHttpParams localBasicHttpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 15000);
        HttpConnectionParams.setSoTimeout(localBasicHttpParams, 15000);
        DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(localBasicHttpParams);
        HttpGet localHttpGet = new HttpGet("https://www.google.com/cloudprint/printer?output=json&printerid=" + this.pid);
        localHttpGet.setHeader("User-Agent", App.getUserAgent());
        localHttpGet.setHeader("Authorization", "GoogleLogin auth=" + ActivityStart.this.prefs.getString("cloud_token", ""));
        localHttpGet.setHeader("X-CloudPrint-Proxy", "PrinterShare");
        HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpGet);
        if (localHttpResponse.getStatusLine().getStatusCode() == 200)
        {
          ActivityCloudPrinters.GPrinterList localGPrinterList = (ActivityCloudPrinters.GPrinterList)Json.read(new BufferedInputStream(localHttpResponse.getEntity().getContent()), ActivityCloudPrinters.GPrinterList.class);
          if (localGPrinterList.printers != null) {
            for (int i = 0; i < localGPrinterList.printers.size(); i++) {
              ActivityStart.this.cloud_printers.add(ActivityCloudPrinters.loadPrinter((ActivityCloudPrinters.GPrinter)localGPrinterList.printers.get(i)));
            }
          }
        }
        Message localMessage;
        return;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        App.reportThrowable(localException);
        localMessage = new Message();
        localMessage.what = 4;
        localMessage.arg1 = -1;
        ActivityStart.this.scanHandler.sendMessage(localMessage);
      }
    }
  }
  
  class LoginThread
    extends Thread
  {
    final int type;
    
    public LoginThread(int paramInt)
    {
      this.type = paramInt;
    }
    
    private void login_ok(Element paramElement)
    {
      ActivityCore.token = XmlUtil.getFirstNodeValue(paramElement, "token");
      ActivityCore.user = new User();
      ActivityCore.user.readFromXml(XmlUtil.getFirstElement(paramElement, "user"));
      ActivityCore.remote_printers = new Vector();
      NodeList localNodeList = paramElement.getElementsByTagName("printer");
      int i = localNodeList.getLength();
      for (int j = 0; j < i; j++)
      {
        Printer localPrinter = new Printer();
        localPrinter.readFromXml((Element)localNodeList.item(j));
        ActivityCore.remote_printers.add(localPrinter);
      }
      SharedPreferences.Editor localEditor = ActivityStart.this.prefs.edit();
      localEditor.putString("token", ActivityCore.token);
      localEditor.putString("login", ActivityCore.user.login);
      localEditor.commit();
    }
    
    public void run()
    {
      ActivityCore.user = null;
      ActivityCore.remote_printers = null;
      ActivityStart.this.last_error = null;
      try
      {
        if (this.type == 3)
        {
          SoapEnvelope localSoapEnvelope1 = new SoapEnvelope("Login", "Param", "data");
          Element localElement1 = localSoapEnvelope1.getDataRoot();
          localElement1.setAttribute("echo", "favorites");
          XmlUtil.appendElement(localElement1, "token", ActivityCore.token);
          ActivityStart.this.addPK(localElement1);
          Element localElement2 = ActivityStart.this.psService.doAction(localSoapEnvelope1).getDataRoot();
          if ("true".equals(localElement2.getAttribute("success"))) {
            login_ok(localElement2);
          }
          while (ActivityStart.this.last_error != null)
          {
            ActivityStart.this.runOnUiThread(new Runnable()
            {
              public void run()
              {
                ActivityStart.this.findViewById(2131230819).setVisibility(8);
                ActivityStart.this.findViewById(2131230821).setVisibility(0);
                ActivityStart.this.findViewById(2131230824).setVisibility(8);
                ActivityStart.this.displayLastError(new DialogInterface.OnClickListener()
                {
                  public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
                  {
                    if (ActivityStart.LoginThread.this.type == 1) {
                      ActivityStart.this.showDialog(1);
                    }
                    while (ActivityStart.LoginThread.this.type != 2) {
                      return;
                    }
                    ActivityStart.this.showDialog(2);
                  }
                });
              }
            });
            ActivityStart.access$902(ActivityStart.this, null);
            return;
            ActivityStart.this.last_error = ("Error: " + XmlUtil.getFirstNodeValue(localElement2, "message"));
          }
        }
      }
      catch (Exception localException)
      {
        for (;;)
        {
          localException.printStackTrace();
          ActivityStart.this.last_error = ("Internal Error: " + localException.getMessage());
          App.reportThrowable(localException);
          continue;
          if (this.type == 2)
          {
            EditText localEditText1 = (EditText)ActivityStart.this.view_dialog_login.findViewById(2131230739);
            EditText localEditText2 = (EditText)ActivityStart.this.view_dialog_login.findViewById(2131230741);
            SoapEnvelope localSoapEnvelope3 = new SoapEnvelope("Login", "Param", "data");
            Element localElement6 = localSoapEnvelope3.getDataRoot();
            localElement6.setAttribute("echo", "favorites");
            XmlUtil.appendElement(localElement6, "login", localEditText1.getText().toString());
            XmlUtil.appendElement(localElement6, "password", localEditText2.getText().toString());
            ActivityStart.this.addPK(localElement6);
            Element localElement7 = ActivityStart.this.psService.doAction(localSoapEnvelope3).getDataRoot();
            if ("true".equals(localElement7.getAttribute("success"))) {
              login_ok(localElement7);
            } else {
              ActivityStart.this.last_error = ("Error: " + XmlUtil.getFirstNodeValue(localElement7, "message"));
            }
          }
          else if (this.type == 1)
          {
            String str1 = ((EditText)ActivityStart.this.view_dialog_register.findViewById(2131230762)).getText().toString();
            String str2 = ((EditText)ActivityStart.this.view_dialog_register.findViewById(2131230764)).getText().toString();
            if (str1.length() != 0)
            {
              if (str2.length() != 0)
              {
                int i = str2.indexOf("@");
                int j = str2.indexOf(".", i + 1);
                if ((i > 0) && (j > i + 1) && (j != -1 + str2.length()))
                {
                  SoapEnvelope localSoapEnvelope2 = new SoapEnvelope("UserRegister", "Param", "data");
                  Element localElement3 = localSoapEnvelope2.getDataRoot();
                  Element localElement4 = XmlUtil.appendElement(localElement3, "user");
                  XmlUtil.appendElement(localElement4, "name", str1);
                  XmlUtil.appendElement(localElement4, "mail", str2);
                  ActivityStart.this.addPK(localElement3);
                  Element localElement5 = ActivityStart.this.psService.doAction(localSoapEnvelope2).getDataRoot();
                  if ("true".equals(localElement5.getAttribute("success"))) {
                    login_ok(localElement5);
                  } else {
                    ActivityStart.this.last_error = ("Error: " + XmlUtil.getFirstNodeValue(localElement5, "message"));
                  }
                }
                else
                {
                  ActivityStart.this.last_error = "Error: Email is not valid.";
                }
              }
              else
              {
                ActivityStart.this.last_error = "Error: Email can't be empty.";
              }
            }
            else
            {
              ActivityStart.this.last_error = "Error: Name can't be empty.";
              continue;
              ActivityStart.this.do_finish(-1);
            }
          }
        }
      }
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.ActivityStart
 * JD-Core Version:    0.7.0.1
 */